/*jshint esversion: 11 */
document.getElementById("clear").addEventListener("click", function () {
  document.getElementById("display").value = "";
});

function get(value) {
  // alert("你好");
  document.getElementById("display").value += value;
}

function calculates() {
  var result = 0;
  result = document.getElementById("display").value;
  document.getElementById("display").value = "";
  document.getElementById("display").value = eval(result);
}
function back() {
  let r = document.getElementById("display").value;
  r = r?.substring(0, r?.length - 1);
  document.getElementById("display").value = r;
}
function log_() {
  let r = document.getElementById("display").value;
  document.getElementById("display").value = "";
  document.getElementById("display").value = Math.log(parseInt(r));
}
function pow() {
  document.getElementById("display").value += "**";
}
function fac() {
  let r = document.getElementById("display").value;
  r = parseInt(r);
  let result = 1;
  while (r) {
    result *= r;
    r--;
  }
  document.getElementById("display").value = result;
}
function sq() {
  let r = parseInt(document.getElementById("display").value);
  document.getElementById("display").value = Math.sqrt(r);
}
function tri(value) {
  let r = parseInt(document.getElementById("display").value);
  if (value == "sin") document.getElementById("display").value = Math.sin(r);
  else if (value == "cos")
    document.getElementById("display").value = Math.cos(r);
  else if (value == "tan")
    document.getElementById("display").value = Math.tan(r);
  else {
    document.getElementById("display").value = "Error!";
  }
}
function add() {
  let r = parseInt(document.getElementById("display").value);
  if (r) {
    if (r > 0) {
      if (document.getElementById("display").value.indexOf("+") > -1)
        document.getElementById("display").value = document
          .getElementById("display")
          .value.replace("+", "-");
      else
        document.getElementById("display").value =
          "+" + document.getElementById("display").value;
    } else if (r < 0) {
      document.getElementById("display").value = document
        .getElementById("display")
        .value.replace("-", "+");
    }
  } else {
    document.getElementById("display").value = "Error";
  }
}
